import dayjs, { Dayjs } from 'dayjs';
import { useCommon } from "@/stores/Common"
import { storeToRefs } from 'pinia'
import { computed, reactive } from 'vue';
const CommonStore = useCommon()

const { SelfDeviceOptions, SecondLeafArr } = storeToRefs(CommonStore)

export const searchConfig = reactive({
    serial: {
        component: 'ASelect',
        label: '设备名称',
        attrs: {
            allowClear: true,
            placeholder: '设备名称',
            showSearch: true,
            options: SelfDeviceOptions,
            filterOption: (input: string, option: any) => {
                return option.label.includes(input)
            },
            style: {
                width: '100%'
            }
        },
    },
    departmentWard: {
        component: "ACascader",
        label: "科室",
        attrs: {
            allowClear: true,
            placeholder: "科室",
            changeOnSelect: true,
            options: SecondLeafArr,
            style: {
                width: '100%'
            }
        },
    },
    TimeArr: {
        component: 'ARangePicker',
        label: '时间',
        attrs: {
            allowClear: true,
            placeholder: ['开始时间', '结束时间'],
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD',
            style: {
                width: '100%'
            }
        }
    },
    alarmType: {
        component: 'ASelect',
        label: '报警类型',
        attrs: {
            allowClear: true,
            placeholder: '请选择报警类型',
            options: [
                { label: '剩余容量不足', value: '剩余容量不足' },
                { label: '取样时间超时', value: '取样时间超时' },
                { label: '手消液超期', value: '手消液超期' },
                { label: '柜门未关闭', value: '柜门未关闭' }
            ],
            style: {
                width: '100%'
            }
        }
    }
})
export const searchSelfConfig = reactive({
    serial: {
        component: 'ASelect',
        label: '设备名称',
        attrs: {
            allowClear: true,
            placeholder: '设备名称',
            showSearch: true,
            options: SelfDeviceOptions,
            filterOption: (input: string, option: any) => {
                return option.label.includes(input)
            },
            style: {
                width: '100%'
            }
        },
    },
    TimeArr: {
        component: 'ARangePicker',
        label: '时间',
        attrs: {
            allowClear: true,
            placeholder: ['开始时间', '结束时间'],
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD',
            style: {
                width: '100%'
            }
        }
    }
})

export const exportConfig = {
    TimeArr: {
        component: 'ARangePicker',
        label: '时间',
        attrs: {
            allowClear: true,
            placeholder: ['开始时间', '结束时间'],
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD',
            defaultPickerValue: [dayjs().subtract(3, 'month'), dayjs().add(0, 'day')],
            disabledDate: (current: Dayjs) => {
                const lastDate = dayjs().subtract(3, 'month')
                const tomorrow = dayjs().add(0, 'day')
                return (lastDate > current || tomorrow < current)
            },
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择时间', trigger: 'blur' }]
    }
}

export const columns = [
    {
        title: '序号',
        dataIndex: 'index',
        align: 'center',
        width: 80,
        fixed: 'left'
    }, {
        title: '科室',
        dataIndex: 'departmentWard',
        width: 300,
        align: 'center',
        customRender: ({ record }: { record: any }) => record.illArea ? `${record.department}-${record.illArea}` : record.department
    }, {
        title: '报警设备名称',
        dataIndex: 'deviceName',
        align: 'center'
    }, {
        title: '序列号',
        dataIndex: 'serial',
        align: 'center'
    }, {
        title: 'SN',
        dataIndex: 'board',
        align: 'center'
    }, {
        title: '报警类型',
        dataIndex: 'alarmType',
        align: 'center'
    }, {
        title: '报警时间',
        dataIndex: 'alarmData',
        align: 'center'
    }
]